<template>
	<a-card :bordered="false">
		<a-form ref="searchFormRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form">
			<a-row :gutter="24">
				<a-col :span="6">
					<a-form-item label="标题" name="flowTitle">
						<a-input v-model:value="searchFormState.flowTitle" placeholder="请输入标题" />
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-form-item label="申请人" name="creator">
						<a-input v-model:value="searchFormState.creator" placeholder="请输入申请人" />
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-form-item label="状态" name="status">
						<a-select v-model:value="searchFormState.status" placeholder="请选择状态" :options="statusOptions" />
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-button type="primary" @click="table.refresh(true)">查询</a-button>
					<a-button style="margin: 0 8px" @click="reset">重置</a-button>
				</a-col>
			</a-row>
		</a-form>
		<s-table
			ref="table"
			:columns="columns"
			:data="loadData"
			bordered
			:row-key="(record) => record.id"
			:tool-config="toolConfig"
		>
			<template #bodyCell="{ column, record }">
				<template v-if="column.dataIndex === 'flowType'">
					{{ $TOOL.dictTypeData('FLOW_TYPE', record.flowType) }}
				</template>
				<template v-if="column.dataIndex === 'duration'">
					{{ $TOOL.flowTimeCovert(record.duration) }}
				</template>
				<template v-if="column.dataIndex === 'status'">
					<span v-if="record.status == '1'" style="background: #5793f1; color: #fff; padding: 3px 10px">{{
						$TOOL.dictTypeData('FLOW_APPROVAL_STATUS', record.status)
					}}</span>
					<span v-if="record.status == '2'" style="background: #a3a6ad; color: #fff; padding: 3px 10px">{{
						$TOOL.dictTypeData('FLOW_APPROVAL_STATUS', record.status)
					}}</span>
					<span v-if="record.status == '3'" style="background: #fa541c; color: #fff; padding: 3px 10px">{{
						$TOOL.dictTypeData('FLOW_APPROVAL_STATUS', record.status)
					}}</span>
					<span v-if="record.status == '4'" style="background: #18ff41; color: #fff; padding: 3px 10px">{{
						$TOOL.dictTypeData('FLOW_APPROVAL_STATUS', record.status)
					}}</span>
					<span v-if="record.status == '5'" style="background: #f56c6c; color: #fff; padding: 3px 10px">{{
						$TOOL.dictTypeData('FLOW_APPROVAL_STATUS', record.status)
					}}</span>
					<span v-if="record.status == '6'" style="background: #bba920; color: #fff; padding: 3px 10px">{{
						$TOOL.dictTypeData('FLOW_APPROVAL_STATUS', record.status)
					}}</span>
					<span v-if="record.status == '7'" style="background: #bba920; color: #fff; padding: 3px 10px">{{
						$TOOL.dictTypeData('FLOW_APPROVAL_STATUS', record.status)
					}}</span>
					<span v-if="record.status == '8'" style="background: #bba920; color: #fff; padding: 3px 10px">{{
						$TOOL.dictTypeData('FLOW_APPROVAL_STATUS', record.status)
					}}</span>
				</template>
				<template v-if="column.dataIndex === 'action'">
					<a-space>
						<a @click="formRef.onHandle(record)">详情</a>
					</a-space>
				</template>
			</template>
		</s-table>
	</a-card>
	<Form ref="formRef" @successful="table.refresh(true)" />
</template>

<script setup name="myTodo">
	import tool from '@/utils/tool'
	import Form from './form.vue'
	import flowJobApi from '@/api/flow/flowJobApi'
	let searchFormState = reactive({})
	const searchFormRef = ref()
	const table = ref()
	const formRef = ref()
	const toolConfig = { refresh: true, height: true, columnSetting: true, striped: false }
	const columns = [
		{
			title: '标题',
			dataIndex: 'flowTitle'
		},
		{
			title: '申请类型',
			dataIndex: 'flowType'
		},
		{
			title: '当前节点',
			dataIndex: 'currentNode'
		},
		{
			title: '申请人',
			dataIndex: 'creator'
		},
		{
			title: '发起时间',
			dataIndex: 'startTime',
			align: 'center',
			width: '200px'
		},
		{
			title: '办理时间',
			dataIndex: 'startTime',
			align: 'center',
			width: '200px'
		},
		{
			title: '办理时长',
			dataIndex: 'duration',
			align: 'center',
			width: '200px'
		},
		{
			title: '状态',
			dataIndex: 'status',
			align: 'center',
			width: '100px'
		}
	]
	// 操作栏通过权限判断是否显示
	columns.push({
		title: '操作',
		dataIndex: 'action',
		align: 'center',
		width: '100px'
	})
	const loadData = (parameter) => {
		const searchFormParam = JSON.parse(JSON.stringify(searchFormState))
		return flowJobApi.findMyDoneTask(Object.assign(parameter, searchFormParam)).then((data) => {
			return data
		})
	}
	// 重置
	const reset = () => {
		searchFormRef.value.resetFields()
		table.value.refresh(true)
	}
	const statusOptions = tool.dictList('FLOW_APPROVAL_STATUS')
</script>
